<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>

    <body>
        <p>数字一：<input type="text" id="yi"></p>
        <p>数字二：<input type="text" id="er"></p>
        <button onclick="s('+')">相加</button>
        <button onclick="s('-')">相减</button>
        <button onclick="s('*')">相乘</button>
        <button onclick="s('/')">相除</button>
        <p>结果：<input type="text" id="jieguo"></p>


        <script>
            function s(e) {
                var text1 = document.querySelector("#yi").value;
                var text2 = document.querySelector("#er").value;
                text1 = Number(text1);
                text2 = Number(text2);
                var sum = 0;
                switch (e) {
                    case '+':
                        sum = text1 + text2;
                        break;
                    case '-':
                        sum = text1 - text2;
                        break;
                    case '*':
                        sum = text1 * text2;
                        break;
                    case '/':
                        sum = text1 / text2;
                        break;
                }
                document.querySelector("#jieguo").value = sum;
            }
        </script>
    </body>

</html>